<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.w3.org/1999/xhtml">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<style>
    .fixed-table-body {
        height: calc(73vh);
    }

    .fixed-table-footer {
        border-top: 0;
    }
</style>
<body class="gray-bg">

<div class="container-div">
    <div class="row">
        <div id="flexSearchBox" class="collapse out col-sm-12 search-box">
            <form id="user-form">
                <div class="select-list">
                    <ul>
                        <li>
                            nameOfShelves：<input type="text" class="reset" name="locationName"/>
                        </li>
                        <li>
                            productName：<input type="text" class="reset" name="productName"/>
                        </li>
                        <li>
                            EAN：<input type="text" class="reset" name="ean"/>
                        </li>
                        <li>
                            SKU：<input type="text" class="reset" name="sku"/>
                        </li>
                        <li>
                            stateOfTheShelves：<select class="reset_select" name="visible"
                                         th:with="type=${@dict.getType('sys_show_hide')}">
                            <option value="">all</option>
                            <option th:each="e : ${type}" th:text="${e['dictLabel']}"
                                    th:value="${e['dictValue']}"></option>
                        </select>
                        </li>
                        <li>
                            company：<select class="reset_select" id="companyId" name="companyId">
                            <option th:each="dep : ${depList}" th:text="${dep.deptName}"
                                    th:value="${dep.deptId}"></option>
                        </select>
                        </li>
                        <li>
                            <a class="btn btn-success btn-rounded btn-sm" onclick="$.treeTable.search()"><i
                                    class="fa fa-search"></i>&nbsp;search</a>
                            <a class="btn btn-primary btn-rounded btn-sm reset-booton"><i
                                    class="glyphicon glyphicon-repeat"></i>&nbsp;reset</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group hidden-xs" id="toolbar" role="group">
            <a class="btn btn-outline btn-success btn-rounded" onclick="$.operate.add(0)"
               shiro:hasPermission="module:location:add">
                <i class="fa fa-plus"></i> add
            </a>
            <a class="btn btn-outline btn-info btn-rounded" onclick="SweepCodeStockTaking('shelves 扫码上架')"
               shiro:hasPermission="module:stockTaking:editSweepCode">
                <i class="fa fa-print"></i> scanPutaway
            </a>
            <a class="btn btn-outline btn-danger btn-rounded" onclick="SweepCodeStockTaking('shelvesX 扫码下架')"
               shiro:hasPermission="module:stockTaking:editSweepCode">
                <i class="fa fa-print"></i> scanPulledOffShelves
            </a>
            <a class="btn btn-outline btn-warning btn-rounded" onclick="SweepCodeStockTaking('shelvesY 扫码移货')"
               shiro:hasPermission="module:stockTaking:editSweepCode">
                <i class="fa fa-print"></i> scanSweepCodeToMoveGoods
            </a>
            <a class="btn btn-outline btn-success btn-rounded" onclick="SweepCodeStockTaking('shelvesJ 捡货')"
               shiro:hasPermission="module:stockTaking:editSweepCode">
                <i class="fa fa-print"></i> picking
            </a>
            <a class="btn btn-outline btn-info btn-rounded" id="expandAllBtn">
                <i class="fa fa-exchange"></i> expand /collapse
            </a>
            <a class="btn btn-outline btn-success btn-rounded" onclick="operationLocation()">
                <i class="fa fa-exchange"></i> location
            </a>
            <a class="btn btn-outline btn-danger btn-rounded flex-botton" data-toggle="collapse"
               data-target="#flexSearchBox">
                <i class="glyphicon glyphicon-chevron-down">unfoldSearch
                </i>
            </a>
        </div>
        <!--定位功能标识-->
        <input type="text" id="fladata">
        <div class="col-sm-12 select-info table-striped">
            <table id="bootstrap-table" ></table>
        </div>
    </div>
</div>
<div th:include="include :: footer"></div>
<script th:src="@{/ajax/libs/select/select2.js}"></script>
<script th:inline="javascript">
    var addFlag = [[${@permission.hasPermi('module:location:add')}]];
    var editFlag = [[${@permission.hasPermi('module:location:edit')}]];
    var removeFlag = [[${@permission.hasPermi('module:location:remove')}]];
    var datas = [[${@dict.getType('sys_show_hide')}]];
    var prefix = ctx + "module/location"

    $(function () {
        var options = {
            id: "locationId",
            parentId: "parentId",
            expandAll: false,
            url: prefix + "/list",
            createUrl: prefix + "/add/{id}",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove/{id}",
            print_label: prefix + "/print_label/{ids}/{createDates}",
            print_labelAsPrintId: prefix + "/print_labelAsPrintId/{ids}/{createDates}",
            modalName: "货物位置",
            columns: [{
                title: 'nameOfShelves',
                field: 'locationName',
                width: '20%',
                formatter: function (value, row, index) {
                    if (row.sumNum == 0 || row.locationType == 'M') {
                        return row.locationName;
                    }
                    return row.locationName + "<span style='color:orangered'>【" + row.sumNum + "】</span>";
                }
            },
                {
                    field: 'productName',
                    title: 'productName',
                    align: "center"
                },
                {
                    field: 'ean',
                    title: 'EAN',
                    align: "center"
                },
                {
                    field: 'sku',
                    title: 'SKU',
                    align: "center"
                },

                {
                    title: 'locationType',
                    field: 'locationType',
                    width: '10%',
                    align: "center",
                    formatter: function (value, item, index) {
                        if (item.locationType == 'M') {
                            return '<span class="label label-success">goodsShelf</span>';
                        }
                        else if (item.locationType == 'C') {
                            return '<span class="label label-primary">grid</span>';
                        }
                        else if (item.locationType == 'F') {
                            return '<span class="label label-warning">cargoBox</span>';
                        }
                        else if (item.locationType == 'H') {
                            return '<span class="label label-danger">cargo</span>';
                        }
                    }
                },
                {
                    field: 'visible',
                    title: 'state',
                    width: '10%',
                    align: "center",
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(datas, row.visible);
                    }
                },
                {
                    field: 'companyName',
                    title: 'company',
                    align: "center",
                },
                {
                    title: 'operation',
                    clickToSelect: false,
                    width: '20%',
                    align: "center",
                    formatter: function (value, row, index) {
                        var actions = [];
                        if (row.locationType == 'F') {
                            actions.push('<a class="btn label-warning btn-xs ' + editFlag + '" href="#" onclick="print_label(\'' + "nobeach" + '\'' + ',\'' + row.locationId + '\'' + ',\'' + row.createDate + '\')"><i class="glyphicon glyphicon-print"></i> cargoBoxLabels</a>');
                        }
                        if (row.locationType == 'H') {
                            actions.push('<a class="btn label-danger btn-xs ' + editFlag + '" href="#" onclick="print_labelAsPrintId(\'' + "nobeach" + '\'' + ',\'' + row.printId + '\'' + ',\'' + row.createDate + '\')"><i class="glyphicon glyphicon-print"></i> productLabels</a>');
                        }
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="$.operate.edit(\'' + row.locationId + '\')"><i class="fa fa-edit"></i>edit</a> ');
                        actions.push('<a class="btn btn-info btn-xs ' + addFlag + '" href="#" onclick="$.operate.add(\'' + row.locationId + '\')"><i class="fa fa-plus"></i>add</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="#" onclick="remove(\'' + row.locationId + '\')"><i class="fa fa-remove"></i>delete</a>');
                        return actions.join('');
                    }
                }]
        };
        $.treeTable.init(options);
    });

    /*定位功能*/
    function operationLocation () {

        var data = $("#fladata").val().split(',')

            for (var z = data.length - 1; z >= 0; z--) {

                    $.treeTable._treeTable.bootstrapTreeTable("toggleRow", data[z])
            }
    }

    function remove (id) {
        $.modal.confirm("Are you sure you want to delete this " + $.table._option.modalName + " message？", function () {
            $.ajax({
                type: 'post',
                url: prefix + "/remove/",
                data: {
                    id: id
                },
                success: function (result) {
                    if (result.code == web_status.SUCCESS) {
                        $.modal.msgSuccess(result.msg);
                        $.treeTable.refresh();
                    } else {
                        $.modal.alertError(result.msg);
                    }
                }
            });
        });
    }

    // tree表格树 展开/折叠
    var expandFlag = false;
    $("#expandAllBtn").click(function () {
        if (expandFlag) {
            $('#bootstrap-table').bootstrapTreeTable('expandAll');
        } else {
            $('#bootstrap-table').bootstrapTreeTable('collapseAll');
        }
        expandFlag = expandFlag ? false : true;
    })

    //扫码上架弹出层
    function SweepCodeStockTaking (title, url) {
        var sign = title.split(" ");
        var url = "";
        //扫码上架
        if (sign[0] == "shelves") {
            url = prefix + "/toSweepCodeLocation?flag=" + sign[0];
            $.modal.open("<h3 style='margin-top: 10px'>" + sign[1] + "</h3>", url);
        } else if (sign[0] == "shelvesX") {
            url = prefix + "/toSweepCodeLocationX?flag=" + sign[0];
            $.modal.open("<h3 style='margin-top: 10px'>" + sign[1] + "</h3>", url);
        } else if (sign[0] == "shelvesY") {
            url = prefix + "/toSweepCodeLocationY?flag=" + sign[0];
            $.modal.open("<h3 style='margin-top: 10px'>" + sign[1] + "</h3>", url);
        } else if (sign[0] == "shelvesJ") {
            url = prefix + "/toSweepCodeLocationJ?flag=" + sign[0];
            $.modal.open("<h3 style='margin-top: 10px'>" + sign[1] + "</h3>", url);
        }
    }


    /*货物位置-打印处理*/
    function print_label (state, ids, createDate) {

        var title;
        //批量打印
        if (state == "beach") {
            var rows = $.common.isEmpty($.table._option.id) ? $.table.selectFirstColumns() : $.table.selectColumns($.table._option.id);
            if (rows.length == 0) {
                $.modal.alertWarning("Please select at least one record");
                return;
            }
            ids = getBootstrapTableValueAsRow('id', rows);
            createDate = getBootstrapTableValueAsRow('createDate', rows);


            title = "batch print"

        } else {
            title = "print"
        }


        var url = $.table._option.print_label.replace("{ids}", ids)
            .replace("{createDates}", createDate);

        $.modal.open(title + $.table._option.modalName, url);

    }

    /*货物位置-打印商品*/
    function print_labelAsPrintId (state, ids, createDate) {

        var title;
        //批量打印
        if (state == "beach") {
            var rows = $.common.isEmpty($.table._option.id) ? $.table.selectFirstColumns() : $.table.selectColumns($.table._option.id);
            if (rows.length == 0) {
                $.modal.alertWarning("Please select at least one record");
                return;
            }
            ids = getBootstrapTableValueAsRow('id', rows);
            createDate = getBootstrapTableValueAsRow('createDate', rows);


            title = "batch print"

        } else {
            title = "print"
        }


        var url = $.table._option.print_labelAsPrintId.replace("{ids}", ids)
            .replace("{createDates}", createDate);

        $.modal.open(title + $.table._option.modalName, url);

    }
</script>
</body>
</html>